const ADDRESSES = require('../helper/coreAssets.json')
const { sumTokens2 } = require('../helper/unwrapLPs');

const MINMAX_B3_POOL = '0x09A1B7d922BcfECa097b06498Bc992A83b0BCc42';
const MINMAX_E4_POOL = '0x89963FCD25Cd3b369A2e0642521BCA7Cf0B9d547';
const MINMAX_M3_POOL = '0xdab7B4D2CA330dde50ce611E2177271fD3Eb3F5F';
const MINMAX_USDT_POOL = '0x074ec23e80bd1fd26b822305614fb10b97847a35';
const MINMAX_XIM_B3_POOL = '0xe409587F043f74e47eFB0C10aAf40808D4e037cE';
const MINMAX_XIM_M3_POOL = '0x73541e9ffb9F4B8d13C2E5621b1Cede1981aD0d9';
const MINMAX_XIM_E3_POOL = '0x2c1B1DE747043f7C7c8e0896EB33b09eD9ED55c5';
const MINMAX_E3_POOL = '0xC264ED05ed2aF451732EF05C480d9e51b92a07aC';
const MINMAX_XIM_E3_METAPOOL = '0x8360D306Be83f9A992b1657Ad68fe08Ca6f2757A';
const MINMAX_XIM_B3_METAPOOL = '0x833d89FA7dD693035678AB53Be792F6F4B352C01';
const MINMAX_XIM_M3_METAPOOL = '0x7B24cAA6a497bc79FDfBAeb8A71a38F15eB3d7F7';

const tokens = {
  // BUSD
  [ADDRESSES.iotex.ioBUSD]:[MINMAX_E4_POOL, MINMAX_XIM_E3_POOL], // decimal: 18
  // USDC
  [ADDRESSES.iotex.ioUSDC]:[MINMAX_E4_POOL, MINMAX_XIM_E3_POOL, MINMAX_E3_POOL, MINMAX_XIM_E3_METAPOOL], // decimal: 6
  // USDT
  [ADDRESSES.iotex.ioUSDT]:[MINMAX_E4_POOL, MINMAX_USDT_POOL, MINMAX_XIM_E3_POOL, MINMAX_E3_POOL, MINMAX_XIM_E3_METAPOOL], // decimal: 6
  // DAI
  [ADDRESSES.iotex.ioDAI]:[MINMAX_E4_POOL, MINMAX_E3_POOL, MINMAX_XIM_E3_METAPOOL], // decimal: 18
  // BUSD_b
  [ADDRESSES.iotex.BUSD_bsc]:[MINMAX_B3_POOL, MINMAX_XIM_B3_POOL, MINMAX_XIM_B3_METAPOOL], // decimal: 18
  // USDC_b
  [ADDRESSES.iotex.USDC_b]:[MINMAX_B3_POOL, MINMAX_XIM_B3_POOL, MINMAX_XIM_B3_METAPOOL], // decimal: 18
  // USDT_b
  [ADDRESSES.iotex.USDT_b]:[MINMAX_B3_POOL, MINMAX_USDT_POOL, MINMAX_XIM_B3_POOL, MINMAX_XIM_B3_METAPOOL], // decimal: 18
  // DAI_m
  [ADDRESSES.iotex.DAI_matic]:[MINMAX_M3_POOL, MINMAX_XIM_M3_POOL, MINMAX_XIM_M3_METAPOOL], // decimal: 18
  // USDT_m
  [ADDRESSES.iotex.USDT_matic]:[MINMAX_M3_POOL, MINMAX_USDT_POOL, MINMAX_XIM_M3_POOL, MINMAX_XIM_M3_METAPOOL], // decimal: 6
  // USDC_m
  [ADDRESSES.iotex.USDC_matic]:[MINMAX_M3_POOL, MINMAX_XIM_M3_POOL, MINMAX_XIM_M3_METAPOOL], // decimal: 6
  // XIM
  [ADDRESSES.iotex.XIM]: [MINMAX_XIM_B3_POOL, MINMAX_XIM_M3_POOL, MINMAX_XIM_E3_POOL, MINMAX_XIM_E3_METAPOOL, MINMAX_XIM_B3_METAPOOL, MINMAX_XIM_M3_METAPOOL] // decimal: 6
};

async function tvl(_, _b, {iotex: block}) {
  let toa = [];

  for (const token in tokens) 
    for(const poolAddress of tokens[token])
      toa.push([token, poolAddress])
  return sumTokens2({chain: 'iotex', block, tokensAndOwners: toa })
}

module.exports = {
    methodology: "All the assets in the pool.",
  iotex:{
    tvl,
  },
};


